#include <bits/stdc++.h>
using namespace std;
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
using ll = long long;
const ll N = 1e5 + 10;
ll u[N], w[N], v[N];
ll a[N], b[N], c[N];

void solve()
{
    ll n;
    cin >> n;
    set<ll> ans[n+1];
    for (ll i = 1; i <= n;i++)
    {
        cin >> u[i] >> v[i] >> w[i];
        if((u[i]-v[i])%w[i]==0)
            ans[i].insert((u[i] - v[i]) / w[i]);
        if ((u[i] - w[i]) % v[i] == 0)
            ans[i].insert((u[i] - w[i]) / v[i]);
        if ((v[i] - w[i]) % u[i] == 0)
            ans[i].insert((v[i] - w[i]) / u[i]);
        if ((v[i] - u[i]) %w[i] == 0)
            ans[i].insert((v[i] - u[i]) / w[i]);
        if ((w[i] - v[i]) % u[i] == 0)
            ans[i].insert((w[i] - v[i]) / u[i]);
        if ((w[i] - u[i]) % v[i] == 0)
            ans[i].insert((w[i] - u[i]) / v[i]);
    }
    map<ll, ll> mp;
    for (ll i = 1; i <= n;i++)
    {
        for(auto j:ans[i])
        {
            if(j>=0)
            mp[j]++;
        }
    }
    for(auto i:mp)
    {
        if(i.second==n&&i.first>=0)
        {
            cout << i.first << endl;
            return;
        }
    }
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    int t = 1;
    cin >> t;
    while(t--)
    {
        solve();
    }
   return 0;
}
